import { apiResponse, axiosInstance } from '../Index';

export interface SecondHandHouseAveragePrice {
  city: string
  district: string
  average_price: number
}

export class SecondHandHouseAveragePriceAPI {
  public static list(city?: string): Promise<SecondHandHouseAveragePrice[]> {
    return new Promise<SecondHandHouseAveragePrice[]>((resolve, reject) => {
      axiosInstance({
        method: 'GET',
        url: 'api/statistic/second-hand-house-average-price/list',
        params: {
          city
        }
      }).then(value => {
        const data: apiResponse = value.data as apiResponse
        resolve(data.data as SecondHandHouseAveragePrice[])
      }).catch(reject)
    })
  }
}
